@using Microsoft.AspNetCore.Components.Authorization
@inject AuthenticationStateProvider AuthenticationStateProvider

@if (isAuthenticated)
{
  <h1>Welcome @userName</h1>
}
@if (!isAuthenticated)
{
  <h1>Please log in!</h1>
}
<AuthorizeView>
  <Authorized>
    <p>State: Authorized</p>
  </Authorized>
  <Authorizing>
    <p>State: Authorizing</p>
  </Authorizing>
  <NotAuthorized>
    <p>State: Not authorized</p>
  </NotAuthorized>
</AuthorizeView>
@code
{
  bool isAuthenticated = false;
  string userName;

  protected override async Task OnParametersSetAsync()
  {
    var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
    isAuthenticated = state.User.Identity.IsAuthenticated;
    userName = state.User.Identity.Name;    
  }
}
